{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=332
  Verdict: Accepted
}
uses SysUtils, Math;
 
const
	eps:double=1e-6;
 
type
	person=record
		n,s:string;
		p:longint;
	end;
 
var
	i,n,kk,cur:longint;
	s1,s2,s3:int64;
	s:string;
	a:array[0..1010] of person;
 
procedure sort(l,r:longint);
var 
	i,j,x:longint;
	y:person;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2].p;
repeat
	while a[i].p>x do inc(i);
	while a[j].p<x do dec(j);
  if i<=j then begin
		y:=a[i];
		a[i]:=a[j];
		a[j]:=y;
    inc(i);
    dec(j);
  end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(n);
for i:=1 to n do begin
	readln(S);
	kk:=pos(' ',s);
	a[i].n:=copy(s,1,kk-1);
	delete(s,1,kk);  
	kk:=pos(' ',s);
	a[i].s:=copy(s,1,kk-1);
	delete(s,1,kk);
	kk:=pos(' ',s);
	s1:=strtoint(copy(s,1,kk-1));
	delete(s,1,kk);
	kk:=pos(' ',s);
	s2:=strtoint(copy(s,1,kk-1));
	delete(s,1,kk);	
	kk:=pos(' ',s);
	if kk=0 then s3:=strtoint(s) else s3:=strtoint(copy(s,1,kk-1));
	cur:=s1+s2+S3;
	a[i].p:=cur;
end;
sort(1,n);
for i:=1 to n do
	writeln(a[i].n,' ',a[i].s);
end.